package com.zhou.bjgl.bjgl.util;

import com.zhou.bjgl.bjgl.business_web.entity.BFileUpload;
import com.zhou.bjgl.bjgl.config.MinioPropertiesConfig;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.FileNotFoundException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.UUID;

/**
 * @ClassName: getFileMsg
 * @Description:
 * @Author: admin
 * @Date: 2021/6/4 21:56
 */
public class GetFileMsg {




    public static BFileUpload getMsg(MultipartFile file){
        BFileUpload fileUpload = new BFileUpload();
        //获取文件大小,转化为以kb为单位的大小
        Double size = Double.parseDouble(String.valueOf(file.getSize())) / 1024;
        BigDecimal b = new BigDecimal(size);
        size = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        fileUpload.setFileSize(size);

        //文件旧文件名
        String fileName = file.getOriginalFilename();
        fileUpload.setOriginFileName(fileName);

        //获取文件类型
        int i = fileName.lastIndexOf(".");
        String sufName = fileName.substring(i);
        fileUpload.setFileType(sufName);

        //新文件名
        String filnameNew = UUID.randomUUID().toString();
        fileUpload.setFileNameInMinio(filnameNew);

        return fileUpload;
    }
}
